package com.azhon.basic.storage.sqlite;

import org.litepal.crud.DataSupport;

import java.util.ArrayList;
import java.util.List;

import androidx.annotation.NonNull;

public class CodeTableOperation {
    
    @NonNull
    private static CodeTableOperation op = new CodeTableOperation();
    private CodeTableOperation(){}
    @NonNull
    private List<CodeTable> list = new ArrayList<>();
    @NonNull
    public static CodeTableOperation getOperation(){
        return op;
    }
    
    /**
     * 存储码表
     * @param tid
     * @param name
     * @param pid
     * @param value
     * @return
     */
    public boolean saveCodeTable(String tid, String name, String pid, String value){
        CodeTable table = new CodeTable(tid, name, pid, value);
        return table.save();
    }
    
    /**
     * 存储码表到列表
     * @param tid
     * @param name
     * @param pid
     * @param value
     * @return
     */
    public void addCodeTable(String tid, String name, String pid, String value){
        CodeTable table = new CodeTable(tid, name, pid, value);
        list.add(table);
    }
    
    public void saveAllCodeTable(){
       CodeTable.saveAll(list);
    }
    
    /**
     * 删除码表
     */
    public void deleteCodeTable(){
        CodeTable.deleteAll(CodeTable.class);
    }
    
    
    /**
     * 是否有数据
     */
    public boolean hasCodeTableRecord() {
        List<CodeTable> codeTables = DataSupport.findAll(CodeTable.class);
        if (codeTables.isEmpty()){
            return false;
        }else{
            return true;
        }
    }
    
}
